{% extends 'admin/public/base.html' %}


{% block con-header %}
<div class="container-fluid am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-9">
            <div class="page-header-heading">
                <span class="am-icon-home page-header-heading-icon"></span>
                订单列表
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block con-footer %}
<div class="row-content am-cf">


	<div class="am-u-sm-12 am-u-md-6 am-u-lg-6">
	    <div class="am-form-group">
	        <div class="am-btn-toolbar">

	        </div>
	    </div>
	</div>
	<!-- 搜索表单 -->
	<form >
		<!-- 搜索条件 -->
	    <div class="am-u-sm-12 am-u-md-6 am-u-lg-3">
	        <div class="am-form-group tpl-table-list-select">
	            <select name="types" data-am-selected="{btnSize: 'sm'}">
	                  <option {% if request.GET.types == 'all' %} selected {% endif %} value="all" >所有类别</option>
	                  <option {% if request.GET.types == 'id' %} selected {% endif %} value="id" >订单号</option>
	                  <option {% if request.GET.types == 'addtime' %} selected {% endif %} value="addtime">订单时间</option>
	                  <option {% if request.GET.types == 'user' %} selected {% endif %} value="user">订单用户</option>
	                  <option {% if request.GET.types == 'totalprice' %} selected {% endif %} value="totalprice">订单总价</option>
	                  <option {% if request.GET.types == 'totalnum' %} selected {% endif %} value="totalnum">商品总数</option>
	                  <option {% if request.GET.types == 'status' %} selected {% endif %} value="status">订单状态</option>
	            </select>
	        </div>
	    </div>
	    <!-- 搜索框 -->
	    <div class="am-u-sm-12 am-u-md-12 am-u-lg-3">
	        <div class="am-input-group am-input-group-sm tpl-form-border-form cl-p">
	            <input name="keywords" type="text" class="am-form-field " value="{{ request.GET.keywords }}">
	            <span class="am-input-group-btn">
					<button class="am-btn  am-btn-default am-btn-success tpl-table-list-field am-icon-search" >
					</button>
				</span>
	        </div>
	    </div>
	</form>

	<!-- 图文列表 -->
	<div class="am-u-sm-12">
	    <table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black ">
	        <thead>
	            <tr>
	            	<th>订单号</th>
					<th>订单时间</th>
	                <th>订单用户</th>
	                <th>订单总价</th>
	                <th>商品总数</th>
	                <th>订单状态</th>
	                <th>订单详情</th>

	            </tr>
	        </thead>
	        <tbody>
	        	{% for v in data %}
	            <tr class="gradeX">
					<!-- 订单号 -->
	                <td class="am-text-middle">{{ v.id }}</td>
	                <!-- 订单时间 -->
	                <td class="am-text-middle">{{ v.addtime|date:'Y-m-d H:i:s' }}</td>
	                <!-- 订单用户 -->
	                <td class="am-text-middle">{{ v.uid.username }}</td>
	                <!-- 订单总价 -->
	                <td class="am-text-middle">{{ v.totalprice }}</td>
	                <!-- 商品数量 -->
	                <td class="am-text-middle">{{ v.totalnum }}</td>
	                <!-- 订单状态 -->
	               	<td class="am-text-middle">
	                	<select oid="{{ v.id }}" class="user_status_save oid" style="color:black">
	                		 <!-- 1-未付款 2-已付款，待发货 3-已发货，代收货 4-已完成 5-已取消 -->
	                		<option value="1" {% if v.status == 1 %} selected {% endif %}>未付款</option>
	                		<option value="2" {% if v.status == 2 %} selected {% endif %}>待发货</option>
	                		<option value="3" {% if v.status == 3 %} selected {% endif %}>已发货</option>
	                		<option value="4" {% if v.status == 4 %} selected {% endif %}>已完成</option>
	                		<option value="5" {% if v.status == 5 %} selected {% endif %}>已取消</option>
		                </select>
	            	</td>
	            	<!-- 订单详情链接 -->
					<td class="am-text-middle">
					    <div class="tpl-table-black-operation">
					        <a href="{% url 'admin_order_info' v.id %}">
					            <i class="am-icon-pencil"></i> 详情
					        </a>
					    </div>
					</td>

	            </tr>
	            {% endfor %}


	            <!-- more data -->
	        </tbody>
	    </table>
	</div>

	<!-- 分页 -->
	<div class="am-u-lg-12 am-cf">
		<div class="am-fr">
		    <ul class="am-pagination tpl-pagination">

		        {% load pagetag %}
		        {% showPage data.paginator.num_pages request %}
		    </ul>
		</div>
	</div>


</div>
<script type="text/javascript">

// 改变订单状态
$('.user_status_save').change(function(){
	// 获取当前的选择状态
	res = $(this).val()
	// 获取用户id
	oid = $(this).attr('oid') 
	// 发送ajax请求修改用户状态
	$.get('{% url "admin_order_status" %}',{oid:oid,status:res});
});

</script>
{% endblock %}